﻿using Factory.MasterData.WorkStations;
using Factory.MesEntity.CustomerDatas;
using Factory.WarehouseManagement.WarehouseSettings;
using IronBarCode;
using Microsoft.AspNetCore.Mvc;
using System.IO;
using System;
using VOL.WebApi;
using System.Threading.Tasks;
using Factory.WarehouseManagement.WarehouseSettings.DTO;

namespace Factory.Web.Controllers.WarehouseManagement
{
    public class WarehouseSetController : Controller
    {
        IWarehouseSetAppService _warehouseSetAppService;

        public WarehouseSetController(IWarehouseSetAppService warehouseSetAppService)
        {
            _warehouseSetAppService = warehouseSetAppService;
        }
        public IActionResult WarehouseSetIndex()
        {
            return View();
        }

        [HttpGet]
        /// <summary>
        /// 获取数据
        /// </summary>
        /// <param name="setName"></param>
        /// <returns></returns>
        public JsonResult GetWarehouseSetList(string? setName, int page, int limit)
        {
            var warehouseSetlist = _warehouseSetAppService.GetListAsync(setName, page, limit);
            return Json(new { data = warehouseSetlist.Result, code = 0 });
        }

        public IActionResult WarehouseSetAddIndex()
        {
            return View();
        }

        [HttpPost]
        public JsonResult AddWarehouseSet(WarehouseSet input)
        {
            var warehouseSetlist = _warehouseSetAppService.CreateAsync(input);
            return Json(new { code = warehouseSetlist, msg = "添加成功" });
        }

        /// <summary>
        /// 删除数据
        /// </summary>
        /// <returns>返回对应数据</returns>
        [HttpPost]
        public JsonResult WarehouseSetDelete(int id)
        {
            var warehouseSetlist = _warehouseSetAppService.DeleteAsync(id);
            return Json(new { code = warehouseSetlist, msg = "删除成功" });
        }

        public ActionResult WarehouseSetUpdateIndex(int id)
        {
            ViewBag.Id = id;
            return View();
        }

        [HttpGet]
        public JsonResult GetWarehouseSetById(int id)
        {
            var warehouselist = _warehouseSetAppService.GetWarehouseSetById(id);
            return Json(new { data = warehouselist, code = 0 });
        }

        [HttpPost]
        public JsonResult UpdateWarehouseSet(WarehouseSetUpdateDTO input)
        {
            var warehouselist = _warehouseSetAppService.UpdateAsync(input);
            return Json(new { code = true, data = warehouselist });
        }


    }
}
